import 'package:flustars/flustars.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_lang/flutter_lang.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:oktoast/oktoast.dart';
import 'package:wallet_home/model/coin_detail_model/coin_detail_list_model.dart';
import 'package:wallet_home/model/wallet_list_model.dart';
import 'package:wallet_home/tools/theme_utils.dart';
import 'package:wallet_home/tools/wallet_list_data.dart';

import '../module_config.dart';

class CoinDetailListWidget extends StatefulWidget {
  final List<CoinDetailModel> list;

  CoinDetailListWidget(this.list);

  @override
  _CoinDetailListWidgetState createState() => _CoinDetailListWidgetState();
}

class _CoinDetailListWidgetState extends State<CoinDetailListWidget> {
  @override
  Widget build(BuildContext context) {
    // List<CoinsBean> list = [];
    return Padding(
        padding: EdgeInsets.only(top: 130, bottom: 60),
        child: ListView.separated(
          // controller: _scrollController,
          itemCount: widget.list.length ?? 0,
          itemBuilder: (context, index) {
            return AnimationConfiguration.staggeredList(
                position: index,
                duration: Duration(milliseconds: 300),
                child: SlideAnimation(
                    verticalOffset: 250.0,
                    child: FadeInAnimation(
                      duration: Duration(milliseconds: 300),
                      child: _buildListItem(widget.list[index]),
                    )));
          },
          separatorBuilder: (context, index) => Divider(
            height: 0.5,
            color: Colors.grey[400],
          ),
        ));
  }

  _buildListItem(CoinDetailModel bean) {
    return InkWell(
      child: Container(
        height: 90,
        color: ThemeUtils.getThemeColor(
            context: context,
            brightnessColor: Colors.white,
            darkColor: Colors.grey[800]),
        width: MediaQuery.of(context).size.width,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Expanded(
              child: Padding(
                padding: EdgeInsets.only(left: 15),
                child: Image.asset(bean.img,
                    width: 35,
                    height: 35,
                    fit: BoxFit.contain,
                    package: ModuleConfig.moduleName),
              ),
              flex: 1,
            ),
            Expanded(
              child: Container(
                margin: EdgeInsets.only(left: 15),
                child: Column(
                  children: [
                    Expanded(
                        flex: 3,
                        child: Row(
                          children: [
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  bean.name,
                                  style: TextStyle(
                                      color: ThemeUtils.getThemeColor(
                                          context: context,
                                          brightnessColor: Colors.grey[800],
                                          darkColor: Colors.white),
                                      fontSize: 16),
                                ),
                                Padding(
                                    padding: EdgeInsets.only(top: 5),
                                    child: Text(
                                      "${bean.time}",
                                      style: TextStyle(
                                          color: ThemeUtils.getThemeColor(
                                              context: context,
                                              brightnessColor: Colors.grey[800],
                                              darkColor: Colors.white),
                                          fontSize: 12),
                                    ))
                              ],

                              ///RenderFlex children have non-zero flex but incoming width constraints are unbounded.
                            ),
                            Spacer(),
                            Padding(
                                padding: EdgeInsets.only(right: 15),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.end,
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Text(
                                      bean.transferType == "0"
                                          ? "- ${bean.upDown}"
                                          : bean.upDown,
                                      style: TextStyle(
                                          color: bean.transferType == "0"
                                              ? Colors.red
                                              : Colors.green,
                                          fontSize: 16),
                                    ),
                                    Padding(
                                        padding: EdgeInsets.only(top: 5),
                                        child: Text(
                                          "${NumUtil.getNumByValueStr(bean.cnyMoney, fractionDigits: 8)} CNY",
                                          style: TextStyle(
                                              color: ThemeUtils.getThemeColor(
                                                  context: context,
                                                  brightnessColor:
                                                      Colors.grey[800],
                                                  darkColor: Colors.white),
                                              fontSize: 12),
                                        ))
                                  ],
                                )),
                          ],
                        )),
                    Container(
                      height: 1,
                      color: Colors.grey[300],
                      margin: EdgeInsets.only(right: 15),
                    ),
                    Expanded(
                        flex: 2,
                        child: Container(
                            padding: EdgeInsets.only(top: 5),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Container(
                                  alignment: Alignment.center,
                                  child: Text(
                                    bean.address,
                                    style: TextStyle(
                                        color: ThemeUtils.getThemeColor(
                                            context: context,
                                            brightnessColor: Colors.grey[800],
                                            darkColor: Colors.white),
                                        fontSize: 13),
                                    overflow: TextOverflow.ellipsis,
                                    maxLines: 1,
                                  ),
                                ),
                                Spacer(),
                                Padding(
                                    padding: EdgeInsets.only(right: 10),
                                    child: InkWell(
                                      child: Icon(Icons.content_copy),
                                      onTap: () {
                                        Clipboard.setData(
                                            ClipboardData(text: bean.address));
                                        showToast("${WXLang.$t("home_copy_text_prompt",package: ModuleConfig.moduleName)}",
                                            position: ToastPosition.bottom);
                                        Clipboard.getData(Clipboard.kTextPlain)
                                            .then((value) => print(
                                                "复制成功======>内容是：${value.text}"));
                                      },
                                    )),
                              ],
                            )
//                            Text.rich(
//                              TextSpan(children: [
//                                TextSpan(text: bean.address),
//                                WidgetSpan(
//                                    child: Padding(
//                                        padding: EdgeInsets.only(left: 25),
//                                        child: InkWell(
//                                          child: Icon(Icons.content_copy),
//                                          onTap: () {
//                                            Clipboard.setData(ClipboardData(
//                                                text: bean.address));
//                                            showToast("复制成功",
//                                                position: ToastPosition.bottom);
//                                            Clipboard.getData(
//                                                    Clipboard.kTextPlain)
//                                                .then((value) => print(
//                                                    "复制成功======>内容是：${value.text}"));
//                                          },
//                                        )),
//                                    alignment: PlaceholderAlignment.middle)
//                              ]),
//                              overflow: TextOverflow.ellipsis,
//                              maxLines: 1,
//                            )
                            ))
                  ],
                ),
              ),
              flex: 6,
            )
          ],
        ),
      ),
      onTap: () {
        // WXNavigator.navigateNamed(context: context, routeName: "/coin_detail");
      },
    );
  }
}
